package com.yhq.spring.i18n.config;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.ResourceBundleMessageSource;

import java.nio.charset.StandardCharsets;

/**
 * Spring 做法，使用TestMessage类启动的时候用
 * @author hqyin
 * @date 2023/4/21 11:39 上午
 */
@Configuration
@ComponentScan(basePackages = "com.yhq.spring.i18n")
@PropertySource("classpath:application.properties")
public class MessageConf {
    @Bean
    public MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasenames("i18n.messages","i18n.messages_en_US","i18n.messages_zh_CN","i18n.messages_zh_TW");
        messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
        return messageSource;
    }
}
